package com.libbase

import com.libbase.extension.filterDuplicates
import com.libbase.utils.JsonUtils
import io.reactivex.rxjava3.subjects.PublishSubject
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.Date

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun dateDeserializer_isCorrect() {
        val date = Date()
        val strDate = JsonUtils.json.toJson(date)
        assertEquals(date.time.toString(), strDate)

        val strJson = """{
            |"date": "$strDate"
            |}""".trimMargin()

        class TestDate(val date: Date)

        var testDate = JsonUtils.json.fromJson(strJson, TestDate::class.java)
        assertEquals(date, testDate.date)

        val gson = JsonUtils.jsonBuilder.create()
        testDate = gson.fromJson(strJson, TestDate::class.java)
        assertEquals(date, testDate.date)
    }

    @Test
    fun observable_test() {
        val test = PublishSubject.create<Int>()

        val disposable = test.filterDuplicates(0)
            .subscribe {

            }

        test.onNext(1)
        test.onNext(2)
        test.onNext(2)
        test.onNext(3)

        disposable.dispose()
    }

    @Test
    fun observing_test() {
        var test: Int by Observing(1, willSet = {

        }, didSet = {

        })

        test = 2
    }
}